package com.cheksin.controller;

import com.cheksin.excl.FileUtil;
import com.cheksin.excl.ReadExcelUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author 不愿透露
 * @Classname IndexController
 * @Description TODO
 * @Date 2021/10/25 13:41
 */
@Controller
public class ExclController {
    @PostMapping("/upload")
    @ResponseBody
    @CrossOrigin//@CrossOrigin(origins = "http://127.0.0.1:8080", maxAge = 3600)
    public String index(@RequestParam("file") MultipartFile file){
        if (file.isEmpty()) {
            return "上传失败，请选择文件";
        };
        try {
            return ReadExcelUtil.readExcelInfo(FileUtil.multipartFileToFile(file));
        }catch (Exception e) {
            return "上传失败，请选择文件:"+e;
        }

    }
}